<html xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jstl/core"
      xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:t="http://myfaces.apache.org/tomahawk">

<f:view>
<f:loadBundle var="text" basename="#{adminTestInstanceList.bundleName}"/>
    <head>
        <title>#{text['testInstanceAdmin.title']}</title>
        <meta name="heading" content="#{text['testInstanceAdmin.heading']}"/>
        <meta name="menu" content="itemMenu"/>
    </head>
<body id="adminTestInstanceList">

 <p>#{text['testInstanceAdmin.message']}</p>

<h:form id="adminInstance" >

<!-- Panel for search criteria -->
<table class="inputFieldsTable">
	<tr>
		<td class="inputLabelColumn"><h:outputLabel for="firstName" value="#{text['user.firstName']}" styleClass="desc"/></td>
		<td><h:inputText id="firstName" value="#{adminTestInstanceList.firstName}"  styleClass="text medium" /></td>
	</tr>
	<tr>
		<td><h:outputLabel for="lastName" value="#{text['user.lastName']}" styleClass="desc"/></td>
		<td><h:inputText value="#{adminTestInstanceList.lastName}" id="lastName" styleClass="text medium"/></td>
	</tr>
	<tr>
		<td><h:outputLabel for="email" value="#{text['user.email']}" styleClass="desc"/></td>
		<td><h:inputText value="#{adminTestInstanceList.email}" id="email" styleClass="text medium"/></td>
	</tr>
	<tr>
		<td><h:outputLabel styleClass="desc"  value="Select Test template"/></td>
		<td>
			<h:selectOneMenu value="#{adminTestInstanceList.chooseTemplate}" id="chooseTemplate" styleclass="select">
				<f:selectItems value="#{adminTestInstanceList.availableTemplate}"/>
			</h:selectOneMenu>
		</td>
		<td><t:message for="lastName" styleClass="fieldError"/></td>
	</tr>
	<tr>
		<td><h:outputLabel styleClass="desc"  value="Select Organization" rendered="#{adminTestInstanceList.superAdminUser}"/></td>
		<td>
			<h:selectOneMenu value="#{adminTestInstanceList.chooseOrganization}" id="chooseOrganization" styleclass="select" 
					 rendered="#{adminTestInstanceList.superAdminUser}">
				<f:selectItems value="#{adminTestInstanceList.availableOrgs}"/>
			</h:selectOneMenu>
		</td>
		<!--td><t:message for="lastName" styleClass="fieldError"/></td-->
	</tr>
</table>


<!-- Panel for search button -->
<span class="buttongroup" >
	<h:commandButton value="Search" action="#{adminTestInstanceList.searchCandidateInstance}" id="submit1" styleClass="button_small" partialSubmit="true"/>
	<h:commandButton value="Done" action="mainMenu" id="cancel" immediate="true" styleClass="button_small" />
</span>

<!-- Search results -->
<h:panelGroup rendered="#{not empty adminTestInstanceList.candidateTestInstance}">
<div class="tests_background">
<t:dataTable  var="testInstance" id="adminListTestInstances" rows="10" 
    value="#{adminTestInstanceList.candidateTestInstance}" sortColumn="#{adminTestInstanceList.sortColumn}"
    sortAscending="#{adminTestInstanceList.ascending}" 
	styleClass="mainTable"
    headerClass="standardTable_Header" 
	rowClasses="rowA,rowB"
    partialTriggers="submit1"
    sortable="true">

    <t:column>
        <f:facet name="header">
            <t:commandSortHeader columnName="objectId" arrow="true">
                <h:outputText value="#{text['testInstance.id']}" />
            </t:commandSortHeader>
        </f:facet>
        <h:outputText value="#{testInstance.objectId}" escape="true"/>
    </t:column>


    <t:column>
        <f:facet name="header">
            <t:commandSortHeader columnName="userName" arrow="true">
                <h:outputText value="User Name" />
            </t:commandSortHeader>
        </f:facet>
        <h:outputText value="#{testInstance.appUser.fullName}" escape="true"/>
    </t:column>
    
    <t:column>
        <f:facet name="header">
            <t:commandSortHeader columnName="org" arrow="true">
                <h:outputText value="Organization" rendered="#{adminTestInstanceList.superAdminUser}"/>
            </t:commandSortHeader>
        </f:facet>
        <h:outputText value="#{testInstance.appUser.orgs.organizationName}" escape="true" rendered="#{adminTestInstanceList.superAdminUser}"/>
    </t:column>
    
    <t:column>
        <f:facet name="header">
            <t:commandSortHeader columnName="testTemplateName" arrow="true">
                <h:outputText value="#{text['testInstance.templateName']}" />
            </t:commandSortHeader>
        </f:facet>
        <h:outputText value="#{testInstance.testTemplate.name}" escape="true"/>
    </t:column>    
    <t:column>
        <f:facet name="header">
            <t:commandSortHeader columnName="testInstanceState" arrow="true">
                <h:outputText value="#{text['testInstance.instanceState']}" />
            </t:commandSortHeader>
        </f:facet>
        <h:outputText value="#{testInstance.testInstanceState.state}" escape="true"/>
    </t:column>
    <t:column>
        <f:facet name="header">
            <t:commandSortHeader columnName="review" arrow="true">
                <h:outputText value=" " />
            </t:commandSortHeader>
        </f:facet>
		<h:panelGroup layout="block">
			<h:commandButton value="Review" action="#{reviewTest.reviewTest}" id="reviewBtn"  rendered="#{testInstance.testInstanceState.state=='COMPLETED'}" styleClass="button_inline" >
				<f:param name="testInstanceObjectId" value="#{testInstance.objectId}"/>
				<f:param name="reviewMode" value="review"/>
			</h:commandButton>
			<h:commandButton value="Show Result" action="#{userTest.inlineReport}" id="resultBtn" rendered="#{testInstance.testInstanceState.state=='COMPLETED'}" styleClass="button_inline">
				<f:param name="testInstanceObjectId" value="#{testInstance.objectId}"/>
			</h:commandButton>
			<h:commandButton value="Send email" action="#{reviewTest.reminderEmail}" id="emailBtn"  rendered="#{testInstance.testInstanceState.state=='READY'}" styleClass="button_inline" >
				<f:param name="testInstanceObjectId" value="#{testInstance.objectId}"/>
			</h:commandButton>
			<h:commandButton value="#{text['testInstance.action.print.results']}" action="#{userTest.PDFReport}"  rendered="#{testInstance.testInstanceState.state=='COMPLETED'}" styleClass="button_inline" >
				<f:param name="testInstanceObjectId" value="#{testInstance.objectId}"/>
			</h:commandButton>
		</h:panelGroup>
    </t:column>
    
</t:dataTable>


<ui:include src="/common/tableFooter.xhtml">
    <ui:param name="tableName" value="adminListTestInstances"/> 
</ui:include>
</div>
</h:panelGroup>
<span class="buttongroup" >
	<h:commandButton value="#{text['testInstance.all.answers.report.button']}" action="#{adminTestInstanceList.assembleData}" styleClass="button_small" rendered="#{adminTestInstanceList.showAssembleButton}"/>
	<h:commandButton value="#{text['testInstance.basic.statistics.button']}" action="#{adminTestInstanceList.generateStatistics}" styleClass="button_small" rendered="#{adminTestInstanceList.showAssembleButton}"/>
	<h:commandButton value="#{text['testInstance.all.answers.report.button']}" styleClass="assemble_data_inactive" rendered="#{adminTestInstanceList.showAssembleWarning}"/>
	<h:commandButton value="#{text['testInstance.basic.statistics.button']}" styleClass="assemble_data_inactive" rendered="#{adminTestInstanceList.showAssembleWarning}"/>
</span>
<h:outputText value="#{text['testInstanceAdmin.single.template.message']}" rendered="#{adminTestInstanceList.showAssembleWarning}"/>
</h:form>
</body>
</f:view>
</html>
